//index.js
//获取应用实例

import {ajax} from "../../utils/httpRequest.js";

Page({
  data: {
    pageData: []
  },
  onLoad: function () {
    this.initData();
  },
  initData() {
    ajax.get('https://api.cloudcpc.com/index.php/home/Applets/getindex', {}, {}, res => {
      this.setData({pageData: res.data});
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    })
  },
  swiperClick(e) {
    let params = e.currentTarget.dataset;
    //console.log(params);
    ajax.post('https://api.cloudcpc.com/index.php/home/Applets/get_recording', {
      appid: params.id
    }, {}, res => {
      wx.navigateToMiniProgram({
        appId: params.appid,
        path: params.path ||'pages/entry/authorize/authorize',
        //path: 'pages/index/index',
        extraData: {},
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log(res);
        },
        fail(error) {
          console.log(error);
        }
      })
    })
  },
  jumpTo(e) {
    let params = e.currentTarget.dataset;
    // console.log(params);
    ajax.post('https://api.cloudcpc.com/index.php/home/Applets/get_recording', {
      appid: params.id
    }, {}, res => {
      wx.navigateToMiniProgram({
        appId: params.appid,
        path: params.path ||'pages/entry/authorize/authorize',
        //path: 'pages/index/index',
        extraData: {},
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log(res);
        },
        fail(error) {
          console.log(error);
        }
      })
    })
  },
  onPullDownRefresh(){
    wx.showNavigationBarLoading();
    this.initData()
  },
  onShareAppMessage(){
    return {
      title: '党建应用商店',
      path: `pages/index/index`,
      success: function (res) {
        console.log('转发成功');
      },
      fail: function (err) {
        console.log('转发失败')
      }
    }
  }
});
